package com.gcc.dao.impl;


import com.gcc.dao.OrderDao;
import com.gcc.pojo.Order;

import java.util.List;

public class OrderDaoImpl extends BaseDao implements OrderDao {
    @Override
    public int saveOrder(Order order) {
        String sql="insert into t_order(order_id,create_time,price,`status`,user_id) value(?,?,?,?,?)";
        return update(sql,order.getOrderId(),order.getCreateTime(),order.getPrice(),order.getStatus(),order.getUserId());

    }

    @Override
    public List<Order> queryOrders() {
        String sql="SELECT `order_id` AS `orderId`,`create_time`AS `createTime`,`price` AS `price`,`status` AS `status`,`user_id`  AS `userId` FROM t_order ";
        return querYForList(Order.class,sql);
    }

    @Override
    public void changeOrderStatus(String orderId, int status) {
        String sql="update t_order set status=? where order_id=?";
        update(sql,status,orderId);
    }

    @Override
    public List<Order> queryOrderByUserId(int userId) {
        String sql="SELECT `order_id` AS `orderId`,`create_time`AS `createTime`,`price` AS `price`,`status` AS `status`,`user_id`  AS `userId` FROM t_order where user_id=?";
        return querYForList(Order.class,sql,userId);
    }
}
